// ----------------------------------------------整体-----------------------------------

import Cookie from './cookie.js'
import Api from  './api.js'
import WApi from  '../wj/api.js'

var tupian1=''                           //您曾经举办过的家宴照片
var tupian2=''                           //您在烹饪中的照片
var tupian3=''                           //您在近期会举办家宴的就餐场所照片

new Vue({
    el:'#applyhost',
    data(){
        return{
            uinfos:[],                              //当前用户
            search:'',                  //------搜索框内容
            sheng:'',                   //------省
            shi:'',                     //------市
            qu:'',                      //------区
            radio1:'',                   //你举办
            checkList2:[],               //形容一
            radio3:'',                   //你有学
            radio4:'',                   //你家宴
            radio5:'',                   //你的家
            radio6:'',                   //你会用
            checkList7:[],               //除了美
            checkList8:[],               //你能为
            radio9:'',                   //你会和
            radio10:'',                   //每个月
            radio11:'',                   //你能接
            radio12:'',                   //你举办
            inpt13:'',                    //具体家
            radio14:'',                   //你还会
            radio15:'',                   //你的年
            radio16:'',                   //形容一
            radio17:'',                   //形容一下
            radio18:'',                   //你所提
            checkList19:[],               //你会提
            radio20:'',                   //你所提
            checked:false,                   //已阅读框
        }
    },
    methods: {
        async info() {                              //---------进行姓名、昵称、头像的赋值------------
            let zh = sessionStorage.getItem("zh")
            let allinfo = await WApi.login()
            for(let i=0;i<allinfo.length;i++){
                if(allinfo[i].zh==zh){
                    this.uinfos=allinfo[i]
                    break
                }
            }
            let citys=[]
            citys=Api.getcity(this.uinfos.city)
            this.sheng=citys[0]
            this.shi=citys[1]
            this.qu=citys[2]
        },
        reset(){
            window.location.href='./applyhost.html'
        },
        commit(){
            this.dateTrue()
        },
        dateTrue(){
            if(this.checked==true){
                if(this.sheng && this.shi && this.qu){
                    if(this.radio1 && this.checkList2 && this.radio3 && this.radio4 && this.radio5 && this.radio6 && this.checkList7 && this.checkList8
                        && this.radio9 && this.radio10 && this.radio11 && this.radio12 && this.inpt13 && this.radio14 && this.radio15 && this.radio16
                        && this.radio17 && this.radio18 && this.checkList19 && this.radio20){
                        if(tupian1 && tupian2 && tupian3){
                            alert(tupian1)
                            alert(tupian2)
                            alert(tupian3)
                            alert(this.uinfos.zh)
                            alert(this.uinfos.name)
                            alert(this.uinfos.email)
                            alert(this.uinfos.phone)
                            //-----------------缺少后台api------------------
                            $.post('http://localhost:8080/hostServlet',{
                                type:"addAll",
                                user_id:this.uinfos.zh,
                                name:this.uinfos.name,
                                address:this.sheng+","+this.shi+","+this.qu,
                                content:this.radio1 +"、"+ this.checkList2 +"、"+ this.radio3 +"、"+ this.radio4 +"、"+ this.radio5 +"、"+ this.radio6 +"、"+ this.checkList7 +"、"+ this.checkList8
                                    +"、"+ this.radio9 +"、"+ this.radio10 +"、"+ this.radio11 +"、"+ this.radio12 +"、"+ this.inpt13 +"、"+ this.radio14 +"、"+ this.radio15 +"、"+ this.radio16
                                    +"、"+ this.radio17 +"、"+ this.radio18 +"、"+ this.checkList19 +"、"+ this.radio20,
                                email:this.uinfos.email,
                                phone:this.uinfos.phone,
                                family_img:tupian1,
                                cooking_img:tupian2,
                                new_img:tupian3,
                            },function f(result) {
                                if(result.success==true){
                                    location.href="./Release.html"
                                }
                            },"json")
                        }else {
                            this.$alert('正在获取图片的路径', '图片合法性检测', {
                                confirmButtonText: '确定',
                            });
                            addImg1()
                            addImg2()
                            addImg3()
                        }
                    }else {
                        this.$alert('信息没填写完整', '信息合法性检测', {
                            confirmButtonText: '确定',
                        });
                    }
                }else {
                    this.$alert('个人基本信息没填写完整,不能注册', '信息合法性检测', {
                        confirmButtonText: '确定',
                    });
                }
            }else {
                this.$alert('请先阅读并同意条款', '信息合法性检测', {
                    confirmButtonText: '确定',
                });
            }

        }
    },
    mounted() {
        if(sessionStorage.getItem("zh")==null){
            this.$alert('请先登录', '系统提示', {
                confirmButtonText: '确定',
                callback: action => {
                    this.$message({
                        type: 'warning',
                        message: '即将跳转到登录界面...'
                    });
                    location.href='./login.html'
                }
            });
        }else{
            this.info()
        }
    }
})

//上传图片
function addImg1() {
    $.ajax({
        url: "http://81.68.126.120:8089/uploadapi/",
        data: new FormData($("#form1")[0]),
        type: "post",
        //cache: false,//上传文件无需缓存
        processData: false,//用于对data参数进行序列化处理 这里必须false
        contentType: false, //必须
        success: function (result) {
            tupian1=result.message
            alert('上传1'+tupian1)
        }
    })
}

function addImg2() {
    $.ajax({
        url: "http://81.68.126.120:8089/uploadapi/",
        data: new FormData($("#form2")[0]),
        type: "post",
        //cache: false,//上传文件无需缓存
        processData: false,//用于对data参数进行序列化处理 这里必须false
        contentType: false, //必须
        success: function (result) {
            tupian2=result.message
            alert('上传2'+tupian2)
        }
    })
}

function addImg3() {
    $.ajax({
        url: "http://81.68.126.120:8089/uploadapi/",
        data: new FormData($("#form3")[0]),
        type: "post",
        //cache: false,//上传文件无需缓存
        processData: false,//用于对data参数进行序列化处理 这里必须false
        contentType: false, //必须
        success: function (result) {
            tupian3=result.message
            alert('上传3'+tupian3)
        }
    })
}

